<template>
	<view class="layout" scroll-y="true">
		<VersionHeader :version_control="isVersionControl"></VersionHeader>
		<view class="" style="display: flex; align-items: center; height: 130rpx;">
			<view class="" style="margin-right: 30rpx;">
				<view class="juzhong" style="font-size: 24rpx; margin-bottom: 10rpx; font-weight: 400; line-height: 17.38px;">
					<view style="margin-right: 160rpx;">提示：</view>
					<view @click="toggleMute" style="width: 50rpx; height: 50rpx;">
					      <img
					        :src="isMuted ? img_url[1] : img_url[0]"
					        style="height: 100%; width: 100%;"
					        alt=""
					      />
					</view>
				</view>
				<view class="" style="width: 300rpx; padding-left: 12rpx; height: 70rpx; margin-left: 12rpx; margin-right: 12rpx; background-color: rgba(85, 82, 242, 0.2); color: rgba(42, 130, 228, 1);" >

					<view class="juzhong">{{tips}}</view>
				</view>
			</view>
			
			<view class="right" style="font-size: 35rpx; margin-right: 20rpx; ">
				<view class="juzhong" style="margin-right: 40rpx;">第
				  <view class="number-sn" style="font-size: 60rpx;">
				    {{group}}
				  </view>
				组</view>
				<view class="juzhong" style="font-size: 35rpx;margin-right: 20rpx;">第
				  <view class="number-sn" style="font-size: 60rpx;">
					{{index}}
				  </view>
				个</view>
			</view>
		</view>
		
		<view class="center-datashow" style="">
			<VersionSinglemodule style=""
				v-for="(item, index) in arrs"
				:key="index"
				:info="item"
			></VersionSinglemodule>
		</view>

		<!-- style="border: 1px solid black;" -->
		<view class="juzhong heibian" style="">
			<view class="" style=" width:30% ;  margin-bottom: 10rpx;">
				<view class="juzhong" style="font-size: 34.4rpx; margin-top: 10rpx;">速度损失</view>
				<view class="juzhong" style="font-size: 34.4rpx; margin-bottom: 10rpx;">(V_Loss):</view>
				<!-- <VersionCanvas></VersionCanvas> -->
				<view class="juzhong">
					<div class="pie-chart" :style="{ '--percentage': v_loss }">
					  <span>{{ v_loss }}%</span>
					</div>
				</view>
				
			</view>
			<view class="" style="width: 70%; ">
				<view class="juzhong heibian" style="height: 160rpx; font-size: 34.4rpx;  padding-bottom: 20rpx;">
					<view class="" style=" width: 220rpx; margin-right: 20rpx;">
						<view class="juzhong" style="margin-bottom: 10rpx;">训练目的</view>
						<view class="juzhong">
							<view class="picker juzhong" style="width: 180rpx; height: 50rpx; margin-left: 20rpx; margin-right: 30rpx; border-radius: 6rpx; border: 2rpx solid rgba(121, 72, 234, 1);">
							  <!-- Picker 组件 -->
								<picker mode="selector" :range="options_train_target" @change="onPickerChange_train_target">
									<view class="picker-selected juzhong">
									  {{ aim ? aim : '点击选择' }}
									</view>
								</picker>
							</view>
						</view>
						
					</view>
					<view class="" style="width: 220rpx;">
						<view class="juzhong" style="margin-bottom: 10rpx;">训练动作</view>
						<view class="picker juzhong" style="width:180rpx; height: 50rpx; margin-left: 20rpx; margin-right: 30rpx; border-radius: 6rpx; border: 2rpx solid rgba(121, 72, 234, 1);">
						  <!-- Picker 组件 -->
							<picker mode="selector" :range="options_train_action" @change="onPickerChange_train_action">
								<view class="picker-selected juzhong">
								  {{ action ? action : '点击选择' }}
								</view>
							</picker>
						</view>
						
					</view>
				</view>
				
				<view class="juzhong" style="margin-top: 20rpx;">
					<view class="">
						<view class="juzhong" style="margin-bottom: 20rpx;">
							<view class="juzhong" style="width: 90rpx; ">1RM:</view>
							<view class="juzhong" style="width: 120rpx;">
								<input v-model="rm" @blur="check_burden_value" style="font-size: 24rpx;" type="text" placeholder="输入1RM"/>
							</view>
							<view class="juzhong" style="width: 60rpx; ">KG</view>
						</view>
						<view class="juzhong" style="margin-bottom: 20rpx;">
							<view class="juzhong" style="width: 90rpx; ">负荷:</view>
							<view class="juzhong" style="width: 120rpx;">
								<input v-model="burden" @focus="onInputFocus" class="juzhong" ref="burdenInput"  type="text" style="font-size: 24rpx;" placeholder="建议负荷"/>
							</view>
							
							<view class="juzhong" style="width: 60rpx; ">KG</view>
						</view>
						
					</view>
					<view class="">
						<view class="" style="margin-bottom: 10rpx;">
							<button @click="goOneRm" class="juzhong" style=" font-size: 24rpx; height: 50rpx; width: 150rpx; border: 1px solid rgba(121, 72, 234, 1);">测量1RM</button>
						</view>
						
						<button @click="stop_group" class="juzhong" style=" font-size: 24rpx; height: 50rpx; width: 150rpx; border: 1px solid rgba(121, 72, 234, 1);">结束本组</button>
						<view style="margin-top: 10rpx; color: rgba(0, 0, 0, 0.32); margin-left: 10rpx; font-size: 14rpx; white-space: normal;">(测试后生成本次训练建议负荷)</view>
					</view>
				</view>
			</view>
		</view>
		<view class="float footer">
			<view class="left">
				<button @click="gotoDefine" class="introduction">指标释义</button>
			</view>
			<view class="right">
				<button class="stop-start" @click="try_stopRequest">停止</button>
				<button @click="start_judgement" class="stop-start" style="margin-left: 37.5rpx;">开始</button>
			</view>
		</view>
		<view v-if="showCircle" class="countdown-circle">
		  <text class="countdown-number">{{ countdown }}</text>
		  <text class="tip-text">请保证设备处于竖直方向并静止3s</text>
		</view>
	</view>
</template>

<script>
import VersionHeader  from '@/components/version-header/version-header.vue';
// import VersionFooter from '@/components/version-footer/version-footer.vue';
import VersionCanvas from '@/components/version-canvas/version-canvas.vue';
import VersionSinglemodule from '@/components/profession-singlemodule/profession-singlemodule.vue';
import VueEvent from '../../VueEvent';
	export default {
		components:{
			VersionHeader,
			// VersionFooter,
			VersionCanvas,
			VersionSinglemodule
		},
		data() {
			return {
				isVersionControl: true, // 控制按钮样式的状态
				isMuted: false, // 初始为非静音
				img_url:[
					"../../static/imgs/voice_open.png",
					"../../static/imgs/voice_close.png"
				],
				measured_acceleration_y: [],
				measured_acceleration_x: [],
				measured_acceleration_z: [],
				angular_velocity_y: [],
				angular_velocity_x: [],
				angular_velocity_z: [],
				maxDataLength: 10000, // 定义数组最大长度，可根据实际需求调整
				showCircle: false, // 控制倒计时圆圈是否显示
				countdown: 3, // 倒计时初始数字
				// simple和professional的button颜色
				accelarateData: [
				  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
				],
				intervalId1: null,    // 用于存储定时器ID
				tips: '等待开始中...',
				
				sub_tips :false,
				version: false,
				intervalId: null,  // 用于存储定时器ID
				options_train_target: ['增肌', '增强力量', '提升爆发力'],
				options_train_action: ['深蹲', '卧推', '硬拉'],
				options_target:{
					'增肌':1,
					'增强力量':2,
					'提升爆发力':3,
				},
				options_action:{
					'深蹲':1,
					'卧推':2,
					'硬拉':3,
				},
				aim: '', // 当前选择的选项
				action: '', // 当前选择的选项
				v_loss:30,
				
				group:0,
				index:0,
				rm: '',
				burden: '',
				
				//用于唯一确定负荷弹窗
				burden_Modal:false,
				check_burden:false,
				r: 0,     // 计时器的秒数
				timer: null, // 用来存储定时器ID，方便停止
				arrs:[
					{'name':'平均速度','value':0,'unit':'m/s'},
					{'name':'峰值速度','value':0,'unit':'m/s'},
					{'name':'平均功率','value':0,'unit':'w'},
					{'name':'峰值功率','value':0,'unit':'w'},

					{'name':'平均发力','value':0,'unit':'N'},
					{'name':'发力峰值','value':0,'unit':'N'},
					{'name':'发力率','value':0,'unit':'m/s'},
					{'name':'功率损失','value':0,'unit':'%'},
					
					{'name':'冲量','value':0,'unit':'kgm/s'},
					{'name':'净冲量','value':0,'unit':'kgm/s'},
					{'name':'做功量','value':0,'unit':'J'},
					{'name':'本组做功','value':0,'unit':'J'},
					
					{'name':'功率峰损','value':0,'unit':'%'},
					{'name':'速度峰损','value':0,'unit':'%'},
					{'name':'相对功率','value':0,'unit':'W/KG'},
					{'name':'相对功率峰','value':0,'unit':'m/s'},
					
					{'name':'离心速度','value':0,'unit':'m/s'},
					{'name':'离心峰速','value':0,'unit':'m/s'},
					{'name':'离心时间','value':0,'unit':'s'},
					{'name':'RPD','value':0,'unit':'W/s'},
					
					{'name':'0.2s速度','value':0,'unit':'m/s'},
					{'name':'0.2s功率','value':0,'unit':'w'},
					{'name':'0.2s发力','value':0,'unit':'N'},
					{'name':'0.2s冲量','value':0,'unit':'kgm/s'},
					
					{'name':'卡路里','value':0,'unit':'kcal'},
					{'name':'总卡路里','value':0,'unit':'kcal'},
					{'name':'OPL','value':0,'unit':'kg'},
					{'name':'向心时间','value':0,'unit':'s'},
				]
			}
		},
		mounted() {
			
		},
		// 在页面销毁时停止监听加速度
		destroyed() {
			
		},
		methods: {
			// 播放声音
			playAudio() {
				const innerAudioContext = uni.createInnerAudioContext()
				innerAudioContext.autoplay = false // 是否自动开始播放，默认为 false
				innerAudioContext.loop = false // 是否循环播放，默认为 false
				uni.setInnerAudioOption({ // ios在静音状态下能够正常播放音效
					obeyMuteSwitch: false, // 是否遵循系统静音开关，默认为 true。当此参数为 false 时，即使用户打开了静音开关，也能继续发出声音。
					success: function(e) {
						console.log('播放成功', e)
					},
					fail: function(e) {
						console.log('播放失败', e)
					}
				})
				innerAudioContext.src = "/pagesTool/static/di.mp3"
				innerAudioContext.play()
			
			},
			onInputFocus() {
				if (this.aim === '' || this.action === '' || this.rm === '') {
					if (!this.burden_Modal) {
						this.burden_Modal = true;
						uni.showModal({
							title: '提示',
							content: '请先完善训练目的，训练动作和1rm的信息',
							showCancel: false,
							confirmText: '我已了解',
							success: (res) => {
								if (res.confirm) {
									console.log('用户点击了确定');
								}
								// 当弹窗关闭后，重置标志位，以便下次还能触发
								this.burden_Modal = false;  
							}
						});
					}
				}
				return false;
			},
			check_burden_value(){
				if(this.aim!=='' && this.action!==''&&this.rm!==''){
					if(!this.check_burden){
						this.check_burden = true ;
						uni.request({
						    url: 'http://182.92.108.71:5001/get_suggest',
						    method: 'POST', // 假设是GET请求，根据实际情况调整请求方式
							  data:{
								  'aim': this.options_target[this.aim] - 1, // 训练目的
								  'action': this.options_action[this.action] - 1, // 训练动作
								  'lrm': this.rm,
							  },
							  header: {
								  'Content-Type': 'application/json', // 根据服务器要求设置 Content-Type
							  },
						    success: (res) => {
						        if (res.statusCode === 200) {
									  // this.accelarateData = res.data.msg;
									  console.log("建议信息：",res.data);
									  uni.showModal({
									    title: '提示',
									    content: '建议负重'+res.data.Suggest[0].toFixed(1)+'kg-'+res.data.Suggest[1].toFixed(1)+'kg',
									    showCancel: false,
									    confirmText: '我已了解',
									    success: (res) => {
									      if (res.confirm) {
									        // console.log('用户点击了确定');
									  	  // 当弹窗关闭后，重置标志位，以便下次还能触发
									  	  this.check_burden = false;  
									      }
									    }
									  });
						        } else {
						            reject(`前置请求失败，状态码：${res.statusCode}`);
						        }
						    },
						    fail: (err) => {
						        reject(`前置请求错误：${err.errMsg}`);
						    },
						});
						
					}
					
				}
			},
			// textToVoice(text){
			// 	var pluginSI = requirePlugin("WechatSI");
			// 	var innerAudioSI = wx.createInnerAudioContext();
			
			// 	pluginSI.textToSpeech({
			// 		lang: "zh_CN",
			// 		tts: true,
			// 		content: text,
			// 		success: function (res) {
			// 			console.log("succ tts", res.filename)
			// 			innerAudioSI.src = res.filename;
			// 			innerAudioSI.play();
			// 		},
			// 		fail: function (res) {
			// 			console.log("fail tts", res)
			// 		}
			// 	});
			// 	return innerAudioSI;
			
			
			// },
			textToVoice(text) {
			    var pluginSI = requirePlugin("WechatSI");
			    var innerAudioSI = wx.createInnerAudioContext();
			  
			    pluginSI.textToSpeech({
			        lang: "zh_CN",
			        tts: true,
			        content: text,
			        success: function (res) {
			            console.log("succ tts", res.filename);
			            innerAudioSI.src = res.filename;
			            innerAudioSI.play();
			
			            // 当语音播放结束时，停止并销毁 innerAudioSI 防止重复播放
			            innerAudioSI.onEnded(() => {
			                console.log("语音播放完毕");
			                innerAudioSI.stop();
			                innerAudioSI.destroy();  // 清理音频对象
			            });
			        },
			        fail: function (res) {
			            console.log("fail tts", res);
			        }
			    });
			    return innerAudioSI;
			},

			toggleMute() {
			  this.isMuted = !this.isMuted;
			},
			start_judgement(){
				if(this.aim===''||this.action===''||this.burden===''||this.rm===''){
					uni.showModal({
					  title: '内容不完整',
					  content: '请确保训练目的，训练动作，负荷，1RM均已填写或选择',
					  showCancel: false,
					  confirmText: '确认',
					});
				}else{
					
					this.showCountdownCircle();
				}
			},
			showCountdownCircle() {
			  if (this.timer) {
			    clearInterval(this.timer); // 清除上一个定时器（防止重复计时）
			  }
			
			  this.tips = '等待开始中...';
			  this.showCircle = true;
			
			  // 启动倒计时定时器
			  const timer = setInterval(() => {
			
			    this.countdown--;
			    if (this.countdown === 0) {
			      clearInterval(timer); // 清除定时器
			      this.showCircle = false;
			      this.countdown = 3; // 重置倒计时数字
			
			      // 倒计时结束后，播放音频和开始请求
				  if (!this.isMuted){
					  this.playAudio();
				  }
			      this.startRequest();
			    }
			  }, 1000);
			},
			try_stopRequest(){
				uni.showModal({
				  // title: '1RM是什么?',
				  content: '确定停止训练吗',
				  showCancel: true,
				  confirmText: '确定',
				  success: (res) => {
				      if (res.confirm) {
				        // 用户点击了确定
						this.stopRequest();
				        // console.log('用户点击确定');
				        // 在这里处理确定后的逻辑
				      } else if (res.cancel) {
				        // 用户点击了取消
				        // console.log('用户点击取消');
				        // 在这里处理取消后的逻辑
				      }
				    },
				});
			},
			stop_group() {
				uni.showModal({
				  // title: '1RM是什么?',
				  content: '确定结束本组训练吗',
				  showCancel: true,
				  confirmText: '确定',
				  success: (res) => {
				      if (res.confirm) {
				        // 增加组的计数
				        this.stopRequest();
				        this.group = this.group + 1;
				        this.index = 0 ;
				        // 初始化 r 为 1，每次点击重新开始计时
				        this.r = 1;
				        
				        // 更新显示提示信息
				        this.updateTips();
				        		
				        // 启动计时器，每隔一秒更新一次 r
				        if (this.timer) {
				          clearInterval(this.timer); // 清除上一个定时器（防止重复计时）
				        }
				        this.startTimer();
				      } 
				    },
				});
				
			},
			startTimer() {
				// 每秒更新一次 r
				this.timer = setInterval(() => {
				  this.r++; // r 值递增
				  this.updateTips(); // 更新显示的提示信息
				}, 1000); // 每秒触发一次
			},
			startTimer() {
				// 每秒更新一次 r
				this.timer = setInterval(() => {
				  this.r++; // r 值递增
				  this.updateTips(); // 更新显示的提示信息
				}, 1000); // 每秒触发一次
			},
				
			// 更新显示的提示信息
			updateTips() {
				this.tips = `组间休息中：${this.r}秒`;
			},
				
			// 如果需要停止计时器，可以调用这个方法
			stopTimer() {
				clearInterval(this.timer); // 清除定时器
				this.timer = null;
			},
			// 停止监听加速度数据
			stopListeningAccelerometer() {
				clearInterval(this.intervalId1); // 停止定时器
			},
			startRequest() {
			  console.log('start to post message');
					this.index = 0 ;
			  if (this.intervalId) {
			    return; // 如果定时器已经存在，防止重复点击
			  }
			  // 使用 setInterval 设置定时器
			  this.intervalId = setInterval(() => {
			    this.send_profession_msg();
				console.log('我发送了一次请求')
			  }, 1000);  // 每隔1000毫秒发送一次请求
			},
			// 停止发送请求
			stopRequest() {
			  console.log('stop to post message');
			  if (this.intervalId) {
			    clearInterval(this.intervalId);  // 清除定时器
			    this.intervalId = null;  // 重置定时器ID
			  }
			},
			gotoDefine(){
				uni.navigateTo({
					url:'/pages/define/define'
				})
			},
			onPickerChange_train_target(event) {
			  const { value } = event.detail;
			  this.aim = this.options_train_target[value];
			  this.check_burden_value();
			},
			onPickerChange_train_action(event) {
			  const { value } = event.detail;
			  this.action = this.options_train_action[value];
			  this.check_burden_value();
			},
			goOneRm() {
				uni.navigateTo({
					url: '/pages/jobOneRm/jobOneRm'
				})
			},
			async send_profession_msg() {
			    // 先向另一个地址发送请求获取数据
			    const preUrl = 'http://182.92.108.71:5001/xyz_to_y'; // 替换为实际的前置请求接口地址
			    try {
			        const preResponse = await new Promise((resolve, reject) => {
			            uni.request({
			                url: preUrl,
			                method: 'POST', // 假设是GET请求，根据实际情况调整请求方式
							  data:{
								  "measured_acceleration_y":VueEvent.sharedData.measured_acceleration_y,
								  "measured_acceleration_x":VueEvent.sharedData.measured_acceleration_x,
								  "measured_acceleration_z":VueEvent.sharedData.measured_acceleration_z,
								  "angular_velocity_y":VueEvent.sharedData.angular_velocity_y,
								  "angular_velocity_x":VueEvent.sharedData.angular_velocity_x,
								  "angular_velocity_z":VueEvent.sharedData.angular_velocity_z,
								  "flag":200
							  },
							  header: {
								  'Content-Type': 'application/json', // 根据服务器要求设置 Content-Type
							  },
			                success: (res) => {
			                    if (res.statusCode === 200) {
										  this.accelarateData = res.data.msg;
										  // console.log("加速度修正成功！！！");
										  // console.log("此时的y轴加速度");
										  // console.log(this.measured_acceleration_y);
										  // console.log("修正后的加速度")
										  // console.log(res.data.msg);
										  
			                        resolve(res.data);
			                    } else {
			                        reject(`前置请求失败，状态码：${res.statusCode}`);
			                    }
			                },
			                fail: (err) => {
			                    reject(`前置请求错误：${err.errMsg}`);
			                },
			            });
			        });
			
			        // 包装请求数据
			        const url = 'http://182.92.108.71:5001/complex'; // 替换为你的接口地址
			        const data = {
			            'aim': this.options_target[this.aim] - 1, // 训练目的
			            'action': this.options_action[this.action] - 1, // 训练动作
			            'lrm': this.rm,
			            'm_data': this.burden,
			            "accelarate_Data": this.accelarateData,  // 使用收集到的加速度数据
			        };
			
			        console.log("发送请求的数据：", data);
			
			        try {
			            // 发送 POST 请求
			            const response = await new Promise((resolve, reject) => {
			                uni.request({
			                    url, // 请求地址
			                    method: 'POST', // 请求方式
			                    data, // 请求数据
			                    header: {
			                        'Content-Type': 'application/json', // 根据服务器要求设置 Content-Type
			                    },
			                    success: (res) => {
			                        if (res.statusCode === 200) {
			                            // 确保 msg 数组存在且不为空
			                            console.log('获取的数据为:', res.data);
			                            if (res.data && res.data.msg && res.data.msg.length > 0) {
			                                const lastMsg = res.data.msg[res.data.msg.length - 1];
			                                if ( lastMsg["第几个"]!== this.index) {
			                                    console.log('数据发生变化');
			                                    // this.group = lastMsg["第几组"];
			                                    this.index = lastMsg["第几个"];
			                                    this.v_loss = (lastMsg["loss"] * 100).toFixed(1);  // 保留两位小数
			                                    
												console.log("修改前",this.arrs[0]['value']);
												console.log("修改后",lastMsg["avg_speed"].toFixed(2));
												this.arrs[0]['value'] = lastMsg["avg_speed"].toFixed(2);  // 平均速度
			                                    this.arrs[1]['value'] = lastMsg["max_speed"].toFixed(2);  // 峰值速度
			                                    this.arrs[2]['value'] = lastMsg["avg_power"].toFixed(2);  // 平均功率
			                                    this.arrs[3]['value'] = lastMsg["max_power"].toFixed(2);  // 峰值功率
												
			                                    this.tips = lastMsg["message"];
												if(lastMsg["message"]==='建议调整重量，减重'||lastMsg["message"]==='建议调整重量,减重'){
													lastMsg["message"]='建议减少重量';
													this.tips = '建议减少重量';
												}else if(lastMsg["message"]==='建议调整重量，增重'||lastMsg["message"]==='建议调整重量,增重'){
													lastMsg["message"]='建议增加重量';
													this.tips = '建议增加重量';
												}
												// 播报 tips 内容
												if(!this.isMuted){
													if(lastMsg["message"]==='请继续训练'){
														this.textToVoice(lastMsg["avg_speed"].toFixed(2) + "米每秒");
													}else{
														this.textToVoice(lastMsg["message"]);
													}
												}
												
												this.arrs[4]['value'] = lastMsg["averagy_force_value"].toFixed(2);//平均发力
												this.arrs[5]['value'] = lastMsg["max_strive"].toFixed(2);//发力峰值
												this.arrs[6]['value'] = lastMsg["strive_rate"].toFixed(2);//发力率
												this.arrs[7]['value'] = lastMsg["power_loss"].toFixed(2);//功率损失
												
												this.arrs[8]['value'] = lastMsg["impulse"].toFixed(2);
												this.arrs[9]['value'] = lastMsg["net_impulse"].toFixed(2);
												this.arrs[10]['value'] = lastMsg["work"].toFixed(2);
												this.arrs[11]['value'] = lastMsg["pre_work"].toFixed(2);
												
												this.arrs[12]['value'] = lastMsg["power_max_loss"].toFixed(2);
												this.arrs[13]['value'] = lastMsg["speed_max_loss"].toFixed(2);
												this.arrs[14]['value'] = lastMsg["relative_power"].toFixed(2);
												this.arrs[15]['value'] = lastMsg["relative_max_power"].toFixed(2);
												
												this.arrs[16]['value'] = lastMsg["centrifugal_speed"].toFixed(2);
												this.arrs[17]['value'] = lastMsg["centrifugal_max_speed"].toFixed(2);
												this.arrs[18]['value'] = lastMsg["centrifugal_time"].toFixed(2);
												this.arrs[19]['value'] = lastMsg["rpd"].toFixed(2);
												
												this.arrs[20]['value'] = lastMsg["zero_point_two_speed"].toFixed(2);
												this.arrs[21]['value'] = lastMsg["zero_point_two_power"].toFixed(2);
												this.arrs[22]['value'] = lastMsg["zero_point_two_strive"].toFixed(2);
												this.arrs[23]['value'] = lastMsg["zero_point_two_momentum"].toFixed(2);
												
												this.arrs[24]['value'] = lastMsg["calorie"].toFixed(2);
												this.arrs[25]['value'] = lastMsg["total_calorie"].toFixed(2);
												this.arrs[26]['value'] = lastMsg["opl"].toFixed(2);
												this.arrs[27]['value'] = lastMsg["toward_heart_time"].toFixed(2);
			                                } else {
			                                    console.log("数据没有变化");
			                                }
											console.log(this.arrs);
			                            } else {
			                                console.error('响应数据格式错误，msg为空或不存在');
			                            }
			                        } else {
			                            reject(`请求失败，状态码：${res.statusCode}`);
			                        }
			                    },
			                    fail: (err) => {
			                        reject(`请求错误：${err.errMsg}`);
			                    },
			                });
			            });
			        } catch (error) {
			            console.error('请求失败：', error);
			        }
			    } catch (preError) {
			        console.error('前置请求失败：', preError);
			    }
			},
		}
	}
</script>

<style>
.countdown-circle {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  border-radius: 100px;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.countdown-number {
  font-size: 50px;
  color: white;
  margin-bottom: 10px;
}
.tip-text {
  color: white;
  text-align: center;
  font-size: 30rpx;
  margin: 20rpx;
  white-space: normal;
}
.train-choose {
  color: rgba(0, 0, 0, 0.15);
  width: 90%;
  // width: 190rpx;
  height: 66rpx;
  // margin-left: 50rpx;
  // border: 1px solid black;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
}
.heibian {
  border-bottom: 1px solid rgba(121, 72, 234, 1);
}
button {
  opacity: 1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(0, 0, 0, 1);
}
.right{
	display: flex;
	justify-content: flex-end;
}
.number-sn{
	width:80rpx;
	display: flex;
	justify-content: center;
}
.juzhong{
	display: flex;
	justify-content: center;
	align-items: center;
	text-align: center;
}
.layout {
  font-weight: 400;
  font-family: 'Source Han Sans', sans-serif;
  white-space: nowrap;
  /* padding: 0px 16px; */
  margin-left: 10rpx;
  margin-right: 10rpx;;
  background-color: rgba(155, 115, 250, 0.05);
/*  height: 100%;
  width: 100%; */
}
input{
	opacity: 1;
	border-radius: 5px;
	background: rgba(255, 255, 255, 1);
	border: 1px solid rgba(121, 72, 234, 1);
}
.center-datashow {
  margin-left: 15rpx;
  margin-right: 15rpx;
  display: grid; /* 使用网格布局 */
  grid-template-columns: repeat(4, 1fr); /* 每行 4 列，均分宽度 */
  gap: 0; /* 移除子元素间的间距 */
  margin: 0; /* 确保父容器没有外边距 */
  padding: 0; /* 确保父容器没有内边距 */
}
/* 扇形统计图 */
.pie-chart {
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  background: conic-gradient(#f4f4ff 0% calc(var(--percentage) * 1%), orange calc(var(--percentage) * 1%) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  --percentage: 40;
}

.pie-chart::after {
  content: '';
  width: 120rpx;
  height: 120rpx;
  background: white;
  border-radius: 50%;
  position: absolute;
  z-index: 1;
}

.pie-chart span {
  position: relative;
  font-size: 35rpx;
  font-weight: bold;
  color: #000000;
  z-index: 2;
}
.footer {
  display: flex;
  justify-content: space-between; /* 左右对齐 */
  align-items: center;
  height: 112.5rpx;
  width: 100%; /* 确保占满父级 */
  box-sizing: border-box;
}

.right {
  display: flex;
  justify-content: flex-end; /* 内容靠右 */
  flex-shrink: 0; /* 防止压缩 */
}

.left{
	display: flex;
	justify-content: flex-start;
}
/* .right{
	display: flex;
	justify-content: flex-end;
	border: 1px solid black;
} */
.introduction{
	margin-top: 20.83rpx;
	width: 237.5rpx;
	height: 58.3rpx;
	display: flex;
	justify-content: center;
	align-items: center;
}
.float {
  display: flex;
}

.stop-start {
  margin-top: 20.83rpx;
  width: 137.5rpx;
  height: 58.3rpx;
  opacity: 1;
  border-radius: 8px;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  /* margin-right: 37.5rpx; */
}
button {
  opacity: 1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(121, 72, 234, 1);
}
</style>
